# *****************************************************
# 实验文件夹: 04_collections_and_containers
# 李承硕
# *****************************************************

from dataclasses import dataclass
from typing import List, Optional


# 学生成绩数据结构
@dataclass
class Student:
    name: str
    score: int


# 成绩管理系统
class GradeManager:
    def __init__(self, students: List[Student]):
        self.students = students

    # 计算平均分
    def averageScore(self) -> float:
        if len(self.students) == 0:
            return 0.0

        total = 0
        for student in self.students:
            total += student.score

        return total / len(self.students)

    # 找出最高分学生
    def topStudent(self) -> Optional[Student]:
        if len(self.students) == 0:
            return None

        top_student = self.students[0]
        for student in self.students:
            if student.score > top_student.score:
                top_student = student

        return top_student

    # 统计及格人数
    def passCount(self, passingScore: int) -> int:
        count = 0
        for student in self.students:
            if student.score >= passingScore:
                count += 1
        return count


# 使用示例
def main() -> int:
    students = [
        Student("张三", 85),
        Student("李四", 92),
        Student("王五", 78),
        Student("赵六", 56),
        Student("钱七", 94)
    ]

    manager = GradeManager(students)

    print(f"平均分: {manager.averageScore()}")
    print(f"及格人数: {manager.passCount(60)}")

    top = manager.topStudent()
    if top is not None:
        print(f"最高分: {top.name} - {top.score}")
    else:
        print("没有学生数据")

    return 0


if __name__ == "__main__":
    main()
